﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Form4
    Sub Genera_Codigo_Pregunta()
        Dim SQL As String = "select Cod_Pregunta from Licitacion_pregunta where Cod_licitacion='" & TextBox1.Text & "'"
        Dim da As SqlDataAdapter
        Dim dt As New DataTable
        Try
            da = New SqlDataAdapter(SQL, nCnn)
            da.Fill(dt)
            If dt.Rows.Count <> 0 Then
                TextBox2.Text = Format(Val(dt.Rows.Count) + 1, "00")
            Else
                TextBox2.Text = "01"
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        NumericUpDown1.Value = 0
        TextBox1.Focus()
    End Sub

    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If Len(TextBox1.Text) <> 0 Then
                TextBox1.Text = Format(Val(TextBox1.Text), "0000")
                Dim SQL As String = "select Cod_Licitacion from Licitacion where Cod_licitacion='" & TextBox1.Text & "'"
                Dim da As SqlDataAdapter
                Dim dt As New DataTable
                Try
                    da = New SqlDataAdapter(SQL, nCnn)
                    da.Fill(dt)
                    If dt.Rows.Count <> 0 Then
                        Call Genera_Codigo_Pregunta()
                        TextBox3.Focus()
                    Else
                        MsgBox("La licitación no ha sido creada", MsgBoxStyle.Critical)
                        TextBox1.Text = ""
                        TextBox1.Focus()
                    End If
                Catch ex As Exception
                    MsgBox(ex.Message, MsgBoxStyle.Critical)
                End Try

            Else
            End If
        End If
       
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class